<template>
  <div>
    <!-- 按钮 -->
    <div class="btns">
            <el-form size="small" inline style="text-align:center">
        <el-form-item label="名称" >
          <el-input 
          placeholder="请输入内容"
          v-model="param.fileName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="loadbaseFile">搜索</el-button>
          <el-button type="primary" size="small" icon="el-icon-edit-outline" @click="toAddHandler">新增</el-button>
          <el-button type="primary" size="small" icon="el-icon-edit-outline" @click="downloadHandler">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- /按钮 -->
    <!-- {{baseFile}} -->
    <!-- 表格 -->
    <el-table size="small" :data="baseFile" border stripe style="width:100%" max-height="500">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="id" prop="id" align="center"></el-table-column>
      <el-table-column label="文件名" prop="fileName" align="center"></el-table-column>
      <el-table-column label="小组名" prop="groupName" align="center"></el-table-column>
      <el-table-column label="加载时间" prop="uploadTime" align="center"></el-table-column>
      <el-table-column label="可执行的文件名" prop="extName" align="center"></el-table-column>
      <el-table-column label="文件大小" prop="fileSize" align="center"></el-table-column>
      <el-table-column label="文件类型" prop="fileType" align="center"></el-table-column>
      <el-table-column label="操作" width="200" align="center">
             <template slot-scope="scope">
        <el-button type="primary" icon="el-icon-edit" circle @click="editHandler(scope.row)"></el-button>
           <el-button type="danger" icon="el-icon-delete" circle @click="deleteHandler(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- /表格 -->
  </div>
</template>
<script>
import {get,post,del} from '@/utils/request'
export default {
  // 页面数据
  data(){ 
    return {
      param:{},
     baseFile:[]
    }
  },
  methods:{
    downloadHandler(){
      window.location.href="http://8.131.68.179:9999/base_file/download?fileName"+this.param.fileName
        },
        // 修改事件处理函数
    editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/baseFile/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },

        deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/base_file/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadbaseFile();
        });
      });
    },

    toAddHandler(){
      this.$router.push("/baseFile/create")
    },
  
  loadbaseFile(){
  let url = "http://8.131.68.179:9999/base_file/select"
  get(url,this.param).then(resp => {
        this.baseFile = resp.data;
      })
    }
},

  // 页面渲染的时候会调用的函数
  created(){
    this.loadbaseFile();
  },
}
</script>